package com.intmall.demo.controller;

import com.intmall.demo.entity.User;
import com.intmall.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author intmall
 * @since 2022-03-02
 */
@RestController
@RequestMapping("/demo/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/list")
    public List<User> list() {
        return userService.list();
    }

    @GetMapping("/save")
    public String save() {
        User user = new User();
        user.setUsername("z3");
        user.setPassword("123");
        userService.addUser(user);
        return "success";
    }

    @GetMapping("/getById")
    public User getById(Long id) {
        return userService.findUserById(id);
    }
}
